package com.db.williamchart.pointtooltip;

import com.db.williamchart.Tooltip;
import ohos.agp.colors.RgbColor;
import ohos.agp.components.*;
import ohos.agp.components.element.ShapeElement;

public class PointTooltip implements Tooltip {
    private Image tooltipView;

    private int drawableRes = ResourceTable.Media_point_tooltip;
    @Override
    public void onCreateTooltip(ComponentContainer parent) {
        if (tooltipView == null){
            tooltipView = (Image) LayoutScatter.getInstance(parent.getContext()).parse(ResourceTable.Layout_point_tooltip,parent,false);

            tooltipView.setImageAndDecodeBounds(drawableRes);
            tooltipView.setVisibility(Component.INVISIBLE);
            parent.addComponent(tooltipView);
        }
    }

    @Override
    public void onDataPointTouch(Float x, Float y) {
    }

    @Override
    public void onDataPointClick(Float x, Float y) {
        if (tooltipView != null){
            tooltipView.setVisibility(Component.VISIBLE);
            tooltipView.setTranslationX((x - tooltipView.getWidth() / 2f) - tooltipView.getLeft());
        }
    }
}
